<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>技术点 | 欢迎来到小张的博客</title><meta name="keywords" content="技术点"><meta name="author" content="Z_SiTong"><meta name="copyright" content="Z_SiTong"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="1）ant-design的使用看官网 https:&#x2F;&#x2F;www.antdv.com&#x2F;components&#x2F;upload-cn&#x2F; 2）IT新闻网站https:&#x2F;&#x2F;www.cnbeta.com&#x2F; 3）用户校验三种方式 用户名和密码 [what you know] 举例子 ant-design-删库被黑客黑掉 用在内部系统（只给内部用）   用户名和密钥(token) [what you have] gi">
<meta property="og:type" content="article">
<meta property="og:title" content="技术点">
<meta property="og:url" content="https://zhang-sitong.gitee.io/blogs/lz_20%20(%E6%8A%80%E6%9C%AF%E7%82%B9)/index.html">
<meta property="og:site_name" content="欢迎来到小张的博客">
<meta property="og:description" content="1）ant-design的使用看官网 https:&#x2F;&#x2F;www.antdv.com&#x2F;components&#x2F;upload-cn&#x2F; 2）IT新闻网站https:&#x2F;&#x2F;www.cnbeta.com&#x2F; 3）用户校验三种方式 用户名和密码 [what you know] 举例子 ant-design-删库被黑客黑掉 用在内部系统（只给内部用）   用户名和密钥(token) [what you have] gi">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/03/29/nHq2BC7guU9e4cP.jpg">
<meta property="article:published_time" content="2019-03-26T06:10:52.000Z">
<meta property="article:modified_time" content="2021-04-15T03:50:11.609Z">
<meta property="article:author" content="Z_SiTong">
<meta property="article:tag" content="技术点">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/03/29/nHq2BC7guU9e4cP.jpg"><link rel="shortcut icon" href="/blogs/img/favicon.png"><link rel="canonical" href="https://zhang-sitong.gitee.io/blogs/lz_20%20(%E6%8A%80%E6%9C%AF%E7%82%B9)/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blogs/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blogs/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

const saveToLocal = {
  // ttl 單位是 天
  set: function setWithExpiry(key, value, ttl) {
    if (ttl === 0) return
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}

// https://stackoverflow.com/questions/16839698/jquery-getscript-alternative-in-native-javascript
const getScript = url => new Promise((resolve, reject) => {
  const script = document.createElement('script')
  script.src = url
  script.async = true
  script.onerror = reject
  script.onload = script.onreadystatechange = function() {
    const loadState = this.readyState
    if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
    script.onload = script.onreadystatechange = null
    resolve()
  }
  document.head.appendChild(script)
})</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-04-15 11:50:11'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><div class="aplayer" data-id="6583040939" data-server="netease" data-type="playlist" data-fixed="true" data-listFolded="false" data-order="random" data-preload="auto"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/lete114/CDN/music/APlayer/APlayer.min.css"><script src="https://cdn.jsdelivr.net/gh/lete114/CDN/music/APlayer/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@1.2.0/dist/Meting.min.js"></script><meta name="generator" content="Hexo 5.3.0"><link rel="alternate" href="/blogs/atom.xml" title="欢迎来到小张的博客" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/blogs/img/%E5%8D%9A%E5%AE%A2%E5%A4%B4%E5%83%8F.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blogs/archives/"><div class="headline">文章</div><div class="length-num">29</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blogs/tags/"><div class="headline">标签</div><div class="length-num">12</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blogs/categories/"><div class="headline">分类</div><div class="length-num">12</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blogs/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/link/"><i class="fa-fw fa fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://i.loli.net/2021/03/29/nHq2BC7guU9e4cP.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blogs/">欢迎来到小张的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blogs/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/archives/"><i class="fa-fw fa fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/link/"><i class="fa-fw fa fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/blogs/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">技术点</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="fa-fw post-meta-icon far fa-calendar-alt"></i><span class="post-meta-label">发表于</span><time datetime="2019-03-26T06:10:52.000Z" title="undefined 2019-03-26 14:10:52">2019-03-26</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blogs/categories/%E6%8A%80%E6%9C%AF%E7%82%B9/">技术点</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="1）ant-design的使用"><a href="#1）ant-design的使用" class="headerlink" title="1）ant-design的使用"></a>1）ant-design的使用</h2><p>看官网 <a target="_blank" rel="noopener" href="https://www.antdv.com/components/upload-cn/">https://www.antdv.com/components/upload-cn/</a></p>
<h2 id="2）IT新闻网站"><a href="#2）IT新闻网站" class="headerlink" title="2）IT新闻网站"></a>2）IT新闻网站</h2><p><a target="_blank" rel="noopener" href="https://www.cnbeta.com/">https://www.cnbeta.com/</a></p>
<h2 id="3）用户校验三种方式"><a href="#3）用户校验三种方式" class="headerlink" title="3）用户校验三种方式"></a>3）用户校验三种方式</h2><ul>
<li>用户名和密码 [what you know]<ul>
<li>举例子 ant-design-删库被黑客黑掉</li>
<li>用在内部系统（只给内部用）</li>
</ul>
</li>
<li>用户名和密钥(token) [what you have]<ul>
<li>gitee通过密钥提交代码</li>
</ul>
</li>
<li>用户名和实体 [who you are]<ul>
<li>成本最高，安全性最高，【用在银行业务，支付宝】</li>
</ul>
</li>
</ul>
<h2 id="4）docker-镜像-容器-仓库"><a href="#4）docker-镜像-容器-仓库" class="headerlink" title="4）docker 镜像 容器 仓库"></a>4）docker 镜像 容器 仓库</h2><p>请点击下面链接地址：<br><a href="https://zhang-sitong.gitee.io/blogs/lz_13/">https://zhang-sitong.gitee.io/blogs/lz_13/</a></p>
<h2 id="5）redis"><a href="#5）redis" class="headerlink" title="5）redis"></a>5）redis</h2><h3 id="账号锁定问题：五分钟以内输错五次密码，锁定账号30分钟"><a href="#账号锁定问题：五分钟以内输错五次密码，锁定账号30分钟" class="headerlink" title="账号锁定问题：五分钟以内输错五次密码，锁定账号30分钟"></a>账号锁定问题：五分钟以内输错五次密码，锁定账号30分钟</h3><ul>
<li><h4 id="第一步-先判断-用户名-black-这个key-是否存在"><a href="#第一步-先判断-用户名-black-这个key-是否存在" class="headerlink" title="第一步 先判断 用户名+black 这个key 是否存在"></a>第一步 先判断 用户名+black 这个key 是否存在</h4><ul>
<li>存在 意味着已经被锁定 所以 立刻return</li>
<li>不存在 继续执行</li>
</ul>
</li>
<li><h4 id="第二步-向数据库进行请求-登录"><a href="#第二步-向数据库进行请求-登录" class="headerlink" title="第二步 向数据库进行请求 登录"></a>第二步 向数据库进行请求 登录</h4><ul>
<li>登录成功 直接返回</li>
<li>登录不成功 进行redis操作</li>
</ul>
</li>
<li><h4 id="第三步-判断是否是第一次输入错误"><a href="#第三步-判断是否是第一次输入错误" class="headerlink" title="第三步 判断是否是第一次输入错误"></a>第三步 判断是否是第一次输入错误</h4><ul>
<li>是 使用incrby进行redis自动累加存储，并expire设置过期时间5分钟，返回输入错误</li>
<li>否 使用get取出用户名这个key的值，判断是否等于5 次<ul>
<li>是 使用set将 用户名+’black’ 这个key存入redis 并expire设置过期时间30分钟，返回账户已锁定</li>
<li>否 使用set用户名更新这个key，并返回输入错误</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="代码如下"><a href="#代码如下" class="headerlink" title="代码如下"></a>代码如下</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Login</span>(<span class="params">APIView</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        username = request.data.get(<span class="string">&#x27;username&#x27;</span>)</span><br><span class="line">        password = request.data.get(<span class="string">&#x27;password&#x27;</span>)</span><br><span class="line">        r = redis.Redis()</span><br><span class="line">        <span class="keyword">if</span> r.get(username + <span class="string">&quot;black&quot;</span>):</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;Sorry，您的账户已经被锁定了，30分钟之后重试&#x27;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">400</span>&#125;)</span><br><span class="line">        user = UserModel.objects.<span class="built_in">filter</span>(username=username, password=password).first()</span><br><span class="line">        <span class="keyword">if</span> user:</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;登录成功&#x27;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>, <span class="string">&#x27;id&#x27;</span>: user.<span class="built_in">id</span>, <span class="string">&#x27;user_level&#x27;</span>: user.user_level&#125;)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 判断是否存在该键值对,如果不存在,则进行创建</span></span><br><span class="line">        <span class="keyword">if</span> r.get(username) == <span class="literal">None</span>:</span><br><span class="line">            r.<span class="built_in">set</span>(username, <span class="number">0</span>)</span><br><span class="line"></span><br><span class="line">        <span class="comment">#  如果是第一次密码错误,开始计时</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">int</span>(r.get(username)) == <span class="number">0</span>:</span><br><span class="line">            r.expire(username, <span class="number">200</span>)</span><br><span class="line">            <span class="comment"># 累加</span></span><br><span class="line">            r.incrby(username, <span class="number">1</span>)</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&quot;msg&quot;</span>: <span class="string">&quot;您输入的用户名或密码错误&quot;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">400</span>&#125;)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="comment"># 在五分钟错误五次 进行封禁</span></span><br><span class="line">            <span class="keyword">if</span> <span class="built_in">int</span>(r.get(username)) == <span class="number">5</span>:</span><br><span class="line">                r.<span class="built_in">set</span>(username + <span class="string">&quot;black&quot;</span>, <span class="built_in">str</span>(password))</span><br><span class="line">                <span class="comment"># 封禁时间</span></span><br><span class="line">                r.expire(username + <span class="string">&quot;black&quot;</span>, <span class="number">1800</span>)</span><br><span class="line">                <span class="keyword">return</span> Response(&#123;<span class="string">&quot;msg&quot;</span>: <span class="string">&quot;您的账号被锁定30分钟&quot;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">400</span>&#125;)</span><br><span class="line">            <span class="comment"># 进行累加</span></span><br><span class="line">            r.incrby(username, <span class="number">1</span>)</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&quot;msg&quot;</span>: <span class="string">&quot;用户名或密码错误&quot;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">400</span>, &#125;)</span><br></pre></td></tr></table></figure>
<h2 id="6）异步"><a href="#6）异步" class="headerlink" title="6）异步"></a>6）异步</h2><p><code>异步方法必须用async关键字声明</code><br><code>耗时任务都需要加上await关键字，await必须依靠async</code></p>
<h3 id="异步的好处：可以同时发多个请求"><a href="#异步的好处：可以同时发多个请求" class="headerlink" title="异步的好处：可以同时发多个请求"></a>异步的好处：可以同时发多个请求</h3><h3 id="异步发送100次请求"><a href="#异步发送100次请求" class="headerlink" title="异步发送100次请求:"></a>异步发送100次请求:</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 异步调用</span></span><br><span class="line"><span class="keyword">import</span> httpx</span><br><span class="line"><span class="keyword">import</span> asyncio</span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line">url = <span class="string">&#x27;http://127.0.0.1:8000/p8/user&#x27;</span></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">def</span> <span class="title">request</span>(<span class="params">client</span>):</span></span><br><span class="line">    r = <span class="keyword">await</span> client.get(url)</span><br><span class="line">    print(r.json())</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">def</span> <span class="title">main</span>():</span></span><br><span class="line">    <span class="keyword">async</span> <span class="keyword">with</span> httpx.AsyncClient() <span class="keyword">as</span> client:</span><br><span class="line">        <span class="comment"># 100 次调用</span></span><br><span class="line">        task_list = []</span><br><span class="line">        <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">100</span>):</span><br><span class="line">            req = request(client)</span><br><span class="line">            task = asyncio.create_task(req)</span><br><span class="line">            task_list.append(task)</span><br><span class="line">        <span class="keyword">await</span> asyncio.gather(*task_list)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&quot;__main__&quot;</span>:</span><br><span class="line">    <span class="comment">#开始</span></span><br><span class="line">    start = time.time()</span><br><span class="line">    asyncio.run(main())</span><br><span class="line">    <span class="comment"># 结束</span></span><br><span class="line">    end = time.time()</span><br><span class="line">    print(<span class="string">f&#x27;异步：发送100次请求，耗时：<span class="subst">&#123;end - start&#125;</span>&#x27;</span>)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="异步写文件"><a href="#异步写文件" class="headerlink" title="异步写文件:"></a>异步写文件:</h3><p><code>aiofiles用于处理asyncio应用程序中的本地磁盘文件。爬虫过程中用它来进行文件的异步操作</code></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">def</span> <span class="title">write</span>(<span class="params">f</span>):</span></span><br><span class="line">    <span class="keyword">await</span> f.write(<span class="string">&quot;欢迎来到缅甸北部\n&quot;</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">def</span> <span class="title">fun</span>():</span></span><br><span class="line">    <span class="keyword">async</span> <span class="keyword">with</span> aiofiles.<span class="built_in">open</span>(<span class="string">&quot;10000.txt&quot;</span>, <span class="string">&#x27;a&#x27;</span>) <span class="keyword">as</span> f:</span><br><span class="line">        <span class="comment"># 列表推导式调用，更快，效率更高 </span></span><br><span class="line">        task = [asyncio.create_task(write(f)) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10000</span>)]</span><br><span class="line">        <span class="comment"># 普通列表 相对于列表推导式要慢一点</span></span><br><span class="line">        <span class="comment"># test_list = []</span></span><br><span class="line">        <span class="comment"># for i in range(10000):</span></span><br><span class="line">        <span class="comment">#     w = write(f)</span></span><br><span class="line">        <span class="comment">#     task = asyncio.create_task(w)</span></span><br><span class="line">        <span class="comment">#     test_list.append(task)</span></span><br><span class="line">        <span class="keyword">await</span> asyncio.gather(*task)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    start = time.time()</span><br><span class="line">    asyncio.run(fun())</span><br><span class="line">    end = time.time()</span><br><span class="line">    print(<span class="string">&quot;执行了%d秒&quot;</span> % (end - start))</span><br></pre></td></tr></table></figure>
<h3 id="用队列实现异步修改用户名"><a href="#用队列实现异步修改用户名" class="headerlink" title="用队列实现异步修改用户名"></a>用队列实现异步修改用户名</h3><h4 id="1-封装redis"><a href="#1-封装redis" class="headerlink" title="1. 封装redis"></a>1. 封装redis</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyRedisQueue</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self, key, **redis_kwargs</span>):</span></span><br><span class="line">        self.__db = redis.Redis(**redis_kwargs)</span><br><span class="line">        self.key = key</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">push</span>(<span class="params">self, key, value</span>):</span></span><br><span class="line">        self.__db.lpush(key, value)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">lrange</span>(<span class="params">self, key</span>):</span></span><br><span class="line">        <span class="keyword">return</span> self.__db.lrange(key, <span class="number">0</span>, -<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">llen</span>(<span class="params">self, key</span>):</span></span><br><span class="line">        <span class="keyword">return</span> self.__db.llen(key)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">pop</span>(<span class="params">self</span>):</span></span><br><span class="line">        <span class="keyword">return</span> self.__db.rpop(self.key)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">def</span> <span class="title">dojob</span>():</span></span><br><span class="line">    r = MyRedisQueue(<span class="string">&#x27;queue&#x27;</span>)</span><br><span class="line">    ccc = <span class="string">&#x27;jg&#x27;</span></span><br><span class="line">    <span class="keyword">while</span> <span class="number">1</span>:</span><br><span class="line">        dea = r.pop()</span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> dea:</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            a = <span class="built_in">eval</span>(dea)</span><br><span class="line">            print(a)</span><br><span class="line">            <span class="keyword">if</span> User.objects.<span class="built_in">filter</span>(username=a[<span class="number">1</span>]):</span><br><span class="line">                r.hset(ccc, a[<span class="number">0</span>], <span class="number">400</span>)</span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=a[<span class="number">0</span>]).update(username=a[<span class="number">1</span>])</span><br><span class="line">                r.hset(ccc, a[<span class="number">0</span>], <span class="number">200</span>)</span><br></pre></td></tr></table></figure>
<h4 id="2-实现异步消费"><a href="#2-实现异步消费" class="headerlink" title="2. 实现异步消费"></a>2. 实现异步消费</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">r = MyRedisQueue(<span class="string">&#x27;queue&#x27;</span>, decode_responses=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Update</span>(<span class="params">APIView</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        <span class="built_in">id</span> = request.query_params.get(<span class="string">&#x27;id&#x27;</span>)</span><br><span class="line">        <span class="comment"># print(r.lrange(key))</span></span><br><span class="line">        <span class="comment"># list = r.lrange()</span></span><br><span class="line">        loop = asyncio.new_event_loop()</span><br><span class="line">        asyncio.set_event_loop(loop)</span><br><span class="line">        res = loop.run_until_complete(dojob())</span><br><span class="line">        loop.close()</span><br><span class="line"></span><br><span class="line">        a = r.hget(<span class="string">&#x27;jg&#x27;</span>, <span class="built_in">id</span>)</span><br><span class="line">        print(a)</span><br><span class="line">        <span class="keyword">if</span> a == <span class="string">&#x27;200&#x27;</span>:</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&quot;msg&quot;</span>: <span class="string">&#x27;修改成功&#x27;</span>&#125;)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;用户名重复&#x27;</span>&#125;)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">UpdateUser</span>(<span class="params">APIView</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        <span class="built_in">id</span> = request.query_params.get(<span class="string">&#x27;id&#x27;</span>)</span><br><span class="line">        vip = request.data.get(<span class="string">&#x27;vip&#x27;</span>)</span><br><span class="line">        new_username = request.data.get(<span class="string">&#x27;new_username&#x27;</span>)</span><br><span class="line">        r.push(<span class="string">&#x27;queue&#x27;</span>,<span class="string">f&#x27;<span class="subst">&#123;<span class="built_in">id</span>, new_username, vip&#125;</span>&#x27;</span>)</span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;正在审核&#x27;</span>&#125;)</span><br></pre></td></tr></table></figure>
<h2 id="7）权限系统"><a href="#7）权限系统" class="headerlink" title="7）权限系统"></a>7）权限系统</h2><p><code>目的是做限制</code></p>
<h3 id="权限模型三种：ACL-ABAC-RBAC"><a href="#权限模型三种：ACL-ABAC-RBAC" class="headerlink" title="权限模型三种：ACL/ABAC/RBAC"></a>权限模型三种：ACL/ABAC/RBAC</h3><pre><code>ACL：面向用户的权限授权（只要有一个新用户，就得授一次权，比较麻烦）
ABAC：基于属性的权限模型
RBAC：基于角色的访问控制</code></pre>
<h3 id="用户权限"><a href="#用户权限" class="headerlink" title="用户权限"></a>用户权限</h3><h4 id="完成ACL权限控制，单数用户访问用户管理，双数用户访问用户详情"><a href="#完成ACL权限控制，单数用户访问用户管理，双数用户访问用户详情" class="headerlink" title="完成ACL权限控制，单数用户访问用户管理，双数用户访问用户详情"></a>完成ACL权限控制，单数用户访问用户管理，双数用户访问用户详情</h4><ul>
<li><h4 id="中间件"><a href="#中间件" class="headerlink" title="中间件"></a>中间件</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MyMiddlewareMixin</span>(<span class="params">MiddlewareMixin</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">process_request</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        <span class="keyword">if</span> <span class="built_in">id</span>:</span><br><span class="line">            <span class="comment"># user = User_Identity.objects.filter(user_id=uid).first()</span></span><br><span class="line">            request.level = <span class="built_in">int</span>(<span class="built_in">id</span>) &amp; <span class="number">1</span></span><br></pre></td></tr></table></figure></li>
<li><h4 id="settings配置"><a href="#settings配置" class="headerlink" title="settings配置"></a>settings配置</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">&#x27;userapp.views.MyMiddlewareMixin&#x27;</span></span><br></pre></td></tr></table></figure></li>
<li><h4 id="修改用户权限视图"><a href="#修改用户权限视图" class="headerlink" title="修改用户权限视图"></a>修改用户权限视图</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Jurisdiction</span>(<span class="params">APIView</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        <span class="keyword">return</span> Response(Jurisdic == request.level)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">put</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        <span class="keyword">global</span> Jurisdic</span><br><span class="line">        Jurisdic = <span class="built_in">int</span>(<span class="keyword">not</span> Jurisdic)</span><br><span class="line">        print(Jurisdic)</span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;已修改&#x27;</span>&#125;)</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Vue路由守卫"><a href="#Vue路由守卫" class="headerlink" title="Vue路由守卫"></a>Vue路由守卫</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">// 用户管理</span><br><span class="line">      &#123;</span><br><span class="line">        path: <span class="string">&#x27;/user&#x27;</span>,</span><br><span class="line">        name: <span class="string">&#x27;user&#x27;</span>,</span><br><span class="line">        component: user,</span><br><span class="line">        // 路由守卫</span><br><span class="line">        beforeEnter:(to,from,next)=&gt;&#123;</span><br><span class="line">          var uid=localStorage.getItem(<span class="string">&#x27;uid&#x27;</span>)</span><br><span class="line">            axios.get(<span class="string">&#x27;http://127.0.0.1:8000/z/middle/?uid=&#x27;</span>+uid)</span><br><span class="line">              .then(res=&gt;&#123;</span><br><span class="line">                var level=res.data.middle</span><br><span class="line">                <span class="keyword">if</span>(level)&#123;</span><br><span class="line">                  <span class="built_in">next</span>()</span><br><span class="line">                &#125;</span><br><span class="line">                <span class="keyword">else</span>&#123;</span><br><span class="line">                  message.info(<span class="string">&#x27;您无权限访问！&#x27;</span>)</span><br><span class="line">                &#125;</span><br><span class="line">              &#125;)</span><br><span class="line">        &#125;,</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="8）三方登录"><a href="#8）三方登录" class="headerlink" title="8）三方登录"></a>8）三方登录</h2><ul>
<li><h3 id="微博三方登录"><a href="#微博三方登录" class="headerlink" title="微博三方登录"></a>微博三方登录</h3><p>  请点击以下链接：<br>  <a href="https://zhang-sitong.gitee.io/blogs/lz_4/">https://zhang-sitong.gitee.io/blogs/lz_4/</a></p>
</li>
<li><h3 id="钉钉三方登录"><a href="#钉钉三方登录" class="headerlink" title="钉钉三方登录"></a>钉钉三方登录</h3><ul>
<li><h4 id="获取钉钉二维码"><a href="#获取钉钉二维码" class="headerlink" title="获取钉钉二维码"></a>获取钉钉二维码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">DingDing</span>(<span class="params">APIView</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        app_id = <span class="string">&#x27;&#x27;</span></span><br><span class="line">        redice_url = <span class="string">&#x27;&#x27;</span>  <span class="comment"># 回调地址 </span></span><br><span class="line">        app_secret = <span class="string">&#x27;&#x27;</span></span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">&quot;url&quot;</span>: <span class="string">&#x27;https://oapi.dingtalk.com/connect/qrconnect?appid=&#x27;</span> + app_id +</span><br><span class="line">                                <span class="string">&#x27;&amp;response_type=code&amp;scope=snsapi_login&amp;state=STATE&amp;redirect_uri=&#x27;</span> + redice_url,</span><br><span class="line">                         <span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>&#125;)</span><br></pre></td></tr></table></figure>
</li>
<li><h4 id="获取token"><a href="#获取token" class="headerlink" title="获取token"></a>获取token</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">DingBind</span>(<span class="params">APIView</span>):</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        code = request.query_params.get(<span class="string">&#x27;code&#x27;</span>)</span><br><span class="line">        print(code)</span><br><span class="line">        t = time.time()</span><br><span class="line">        <span class="comment"># 时间戳</span></span><br><span class="line">        timestamp = <span class="built_in">str</span>((<span class="built_in">int</span>(<span class="built_in">round</span>(t * <span class="number">1000</span>))))</span><br><span class="line">        <span class="comment"># 替换成自己的appSecret</span></span><br><span class="line">        appSecret = <span class="string">&#x27;Wrp4YkJ_Aay1lEclT4YUGqvMDHqf4gZJL-TzjOQOEZYpYXz3Ztw07Rq5Igr6KYyU&#x27;</span></span><br><span class="line">        <span class="comment"># 构造签名</span></span><br><span class="line">        signature = base64.b64encode(</span><br><span class="line">            hmac.new(appSecret.encode(<span class="string">&#x27;utf-8&#x27;</span>), timestamp.encode(<span class="string">&#x27;utf-8&#x27;</span>), digestmod=sha256).digest())</span><br><span class="line">        <span class="comment"># 请求接口，换取钉钉用户名</span></span><br><span class="line">        payload = &#123;<span class="string">&#x27;tmp_auth_code&#x27;</span>: code&#125;</span><br><span class="line">        headers = &#123;<span class="string">&#x27;Content-Type&#x27;</span>: <span class="string">&#x27;application/json&#x27;</span>&#125;</span><br><span class="line">        res = requests.post(<span class="string">&#x27;https://oapi.dingtalk.com/sns/getuserinfo_bycode?signature=&#x27;</span> + parse.quote(</span><br><span class="line">            signature.decode(<span class="string">&quot;utf-8&quot;</span>)) + <span class="string">&quot;&amp;timestamp=&quot;</span> + timestamp + <span class="string">&quot;&amp;accessKey=dingoalxhmajgqbhn4ennn&quot;</span>,</span><br><span class="line">                            data=json.dumps(payload), headers=headers)  <span class="comment"># accessKey替换成自己的appid</span></span><br><span class="line">        <span class="comment">#  获取到一个随便的唯一id</span></span><br><span class="line">        res_dict = json.loads(res.text)</span><br><span class="line">        print(res_dict)</span><br><span class="line">        unionid = res_dict[<span class="string">&#x27;user_info&#x27;</span>][<span class="string">&#x27;unionid&#x27;</span>]</span><br><span class="line">        user = User.objects.<span class="built_in">filter</span>(ding=unionid).first()</span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> user:</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;code&#x27;</span>: <span class="number">404</span>, <span class="string">&#x27;unioid&#x27;</span>: unionid&#125;)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>, <span class="string">&#x27;id&#x27;</span>: user.<span class="built_in">id</span>, <span class="string">&#x27;vip&#x27;</span>: user.<span class="built_in">id</span>&#125;)</span><br><span class="line">    <span class="comment"># 绑定已有用户</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        unionid = request.data.get(<span class="string">&#x27;unionid&#x27;</span>, <span class="literal">None</span>)</span><br><span class="line">        created_at = request.data.get(<span class="string">&#x27;created_at&#x27;</span>, <span class="literal">None</span>)</span><br><span class="line">        <span class="built_in">id</span> = request.data.get(<span class="string">&#x27;id&#x27;</span>)</span><br><span class="line">        wyx = request.data.get(<span class="string">&#x27;wyx&#x27;</span>)</span><br><span class="line">        user = User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=<span class="built_in">id</span>).first()</span><br><span class="line">        <span class="keyword">if</span> wyx &amp; <span class="number">1</span> == <span class="number">1</span>:</span><br><span class="line">            User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=<span class="built_in">id</span>).update(ding=unionid)</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&quot;绑定成功&quot;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>, <span class="string">&#x27;id&#x27;</span>: user.<span class="built_in">id</span>, <span class="string">&#x27;vip&#x27;</span>: user.<span class="built_in">id</span>&#125;)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=<span class="built_in">id</span>).update(git=created_at)</span><br><span class="line">            <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&quot;绑定成功&quot;</span>, <span class="string">&#x27;code&#x27;</span>: <span class="number">200</span>, <span class="string">&#x27;id&#x27;</span>: user.<span class="built_in">id</span>, <span class="string">&#x27;vip&#x27;</span>: user.<span class="built_in">id</span>&#125;)</span><br></pre></td></tr></table></figure></li>
<li><h4 id="vue回调地址"><a href="#vue回调地址" class="headerlink" title="vue回调地址"></a>vue回调地址</h4><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;h1&gt;回调&lt;/h1&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">&#x27;axios&#x27;</span></span><br><span class="line">export default &#123;</span><br><span class="line">name: <span class="string">&quot;ding_url&quot;</span>,</span><br><span class="line">  data()&#123;</span><br><span class="line">    <span class="keyword">return</span>&#123;</span><br><span class="line">      code : this.$route.query.code,</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  created() &#123;</span><br><span class="line">    <span class="keyword">if</span>(this.code)&#123;</span><br><span class="line">      axios(&#123;</span><br><span class="line">        url:<span class="string">&#x27;http://127.0.0.1:8000/app2/ding_bind/?code=&#x27;</span>+this.code,</span><br><span class="line">      &#125;).then(res =&gt;&#123;</span><br><span class="line">        <span class="keyword">if</span>(res.data.code==<span class="number">404</span>)&#123;</span><br><span class="line">          this.$router.push(<span class="string">&#x27;/bind/?unionid=&#x27;</span>+res.data.unioid)</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">          localStorage.setItem(<span class="string">&#x27;vip&#x27;</span>,res.data.vip)</span><br><span class="line">          localStorage.setItem(<span class="string">&#x27;id&#x27;</span>,res.data.<span class="built_in">id</span>)</span><br><span class="line">          this.$router.push(<span class="string">&#x27;/myback&#x27;</span>)</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="vue绑定用户"><a href="#vue绑定用户" class="headerlink" title="vue绑定用户"></a>vue绑定用户</h4><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">      &lt;p v-<span class="keyword">for</span>=<span class="string">&quot;i in nr&quot;</span>&gt;</span><br><span class="line">        &#123;&#123;i.username&#125;&#125;---</span><br><span class="line">        &lt;a-button @click=&quot;bind(i.id)&quot;&gt;绑定&lt;/a-button&gt;</span><br><span class="line">      &lt;/p&gt;</span><br><span class="line"></span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line"><span class="keyword">import</span> axios <span class="keyword">from</span> <span class="string">&#x27;axios&#x27;</span></span><br><span class="line">export default &#123;</span><br><span class="line">  name: <span class="string">&quot;bind&quot;</span>,</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      unionid:this.$route.query.unionid,</span><br><span class="line">      created_at:this.$route.query.created_at,</span><br><span class="line">      nr:[],</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  methods:&#123;</span><br><span class="line">    bind(<span class="built_in">id</span>)&#123;</span><br><span class="line">      <span class="keyword">if</span> (this.unionid)&#123;</span><br><span class="line">        axios(&#123;</span><br><span class="line">          url:<span class="string">&#x27;http://127.0.0.1:8000/app2/ding_bind/&#x27;</span>,</span><br><span class="line">          method:<span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">          data:&#123;<span class="string">&#x27;unionid&#x27;</span>:this.unionid,<span class="string">&#x27;id&#x27;</span>:<span class="built_in">id</span>,<span class="string">&#x27;wyx&#x27;</span>:<span class="number">1</span>&#125;</span><br><span class="line">        &#125;).then(res =&gt;&#123;</span><br><span class="line">          <span class="keyword">if</span>(res.data.code == <span class="number">200</span>)&#123;</span><br><span class="line">            localStorage.setItem(<span class="string">&#x27;vip&#x27;</span>,res.data.vip)</span><br><span class="line">            localStorage.setItem(<span class="string">&#x27;id&#x27;</span>,res.data.<span class="built_in">id</span>)</span><br><span class="line">            this.$router.push(<span class="string">&#x27;/myback&#x27;</span>)</span><br><span class="line">          &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            alert(res.data.msg)</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        axios(&#123;</span><br><span class="line">          url:<span class="string">&#x27;http://127.0.0.1:8000/app2/ding_bind/&#x27;</span>,</span><br><span class="line">          method:<span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">          data:&#123;<span class="string">&#x27;created_at&#x27;</span>:this.created_at,<span class="string">&#x27;id&#x27;</span>:<span class="built_in">id</span>,<span class="string">&#x27;wyx&#x27;</span>:<span class="number">10</span>&#125;</span><br><span class="line">        &#125;).then(res =&gt;&#123;</span><br><span class="line">          <span class="keyword">if</span>(res.data.code == <span class="number">200</span>)&#123;</span><br><span class="line">            localStorage.setItem(<span class="string">&#x27;vip&#x27;</span>,res.data.vip)</span><br><span class="line">            localStorage.setItem(<span class="string">&#x27;id&#x27;</span>,res.data.<span class="built_in">id</span>)</span><br><span class="line">            this.$router.push(<span class="string">&#x27;/myback&#x27;</span>)</span><br><span class="line">          &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            alert(res.data.msg)</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  created() &#123;</span><br><span class="line">    axios(&#123;</span><br><span class="line">      url:<span class="string">&#x27;http://127.0.0.1:8000/app2/user/&#x27;</span></span><br><span class="line">    &#125;).then(res =&gt;&#123;</span><br><span class="line">      this.nr = res.data</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure>

</li>
</ul>
</li>
</ul>
<h2 id="9）无限极分类"><a href="#9）无限极分类" class="headerlink" title="9）无限极分类"></a>9）无限极分类</h2><p><code>请点击以下链接，进行查看</code><br><a href="https://zhang-sitong.gitee.io/blogs/lz_11/">https://zhang-sitong.gitee.io/blogs/lz_11/</a></p>
<h2 id="10）MongoDB"><a href="#10）MongoDB" class="headerlink" title="10）MongoDB"></a>10）MongoDB</h2><p><code>请点击以下链接，进行查看</code><br><a href="https://zhang-sitong.gitee.io/blogs/lz_17/">https://zhang-sitong.gitee.io/blogs/lz_17/</a></p>
<h2 id="11）栈"><a href="#11）栈" class="headerlink" title="11）栈"></a>11）栈</h2><ul>
<li><h3 id="栈：先进后出"><a href="#栈：先进后出" class="headerlink" title="栈：先进后出"></a>栈：先进后出</h3></li>
<li><h3 id="写一套方法，基于栈类，实现bin方法（十进制和二进制转换）"><a href="#写一套方法，基于栈类，实现bin方法（十进制和二进制转换）" class="headerlink" title="写一套方法，基于栈类，实现bin方法（十进制和二进制转换）"></a>写一套方法，基于栈类，实现bin方法（十进制和二进制转换）</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#  栈：先进后出</span></span><br><span class="line"><span class="comment"># 类似于：箱子（拿东西和放东西）</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Stack</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span>(<span class="params">self</span>):</span></span><br><span class="line">        self.items = []</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">isEmpty</span>(<span class="params">self</span>):</span>  <span class="comment"># 判栈空</span></span><br><span class="line">        <span class="keyword">return</span> self.items == []</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">push</span>(<span class="params">self, item</span>):</span>  <span class="comment"># 进栈</span></span><br><span class="line">        self.items.append(item)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">pop</span>(<span class="params">self</span>):</span>  <span class="comment"># 出栈</span></span><br><span class="line">        <span class="keyword">return</span> self.items.pop()</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">peek</span>(<span class="params">self</span>):</span>  <span class="comment"># 获取栈顶元素</span></span><br><span class="line">        <span class="keyword">return</span> self.items[<span class="built_in">len</span>(self.items) - <span class="number">1</span>]</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">size</span>(<span class="params">self</span>):</span>  <span class="comment"># 获取栈的大小</span></span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">len</span>(self.items)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 十进制转二进制</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">Switch</span>(<span class="params">Number</span>):</span></span><br><span class="line">    switch = Stack()</span><br><span class="line">    <span class="keyword">while</span> Number &gt; <span class="number">0</span>:</span><br><span class="line">        num = Number % <span class="number">2</span></span><br><span class="line">        switch.push(num)</span><br><span class="line">        Number = Number // <span class="number">2</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 构建二进制字符串</span></span><br><span class="line">    binStr = <span class="string">&#x27;&#x27;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">while</span> <span class="keyword">not</span> switch.isEmpty():</span><br><span class="line">        binStr = binStr + <span class="built_in">str</span>(switch.pop())</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;0b&quot;</span> + binStr</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">print(Switch(<span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">&quot;请输入要转换成二进制的数字： &quot;</span>))))</span><br></pre></td></tr></table></figure>

</li>
</ul>
<h2 id="12）消息盒子"><a href="#12）消息盒子" class="headerlink" title="12）消息盒子"></a>12）消息盒子</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 消息盒子</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MessageView</span>(<span class="params">APIView</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        user_id = request.query_params.get(<span class="string">&#x27;id&#x27;</span>)</span><br><span class="line">        c = r.hgetall(<span class="string">&#x27;user%s&#x27;</span> % user_id)</span><br><span class="line">        list1 = []</span><br><span class="line">        length = <span class="number">0</span></span><br><span class="line">        <span class="keyword">for</span> key, values <span class="keyword">in</span> c.items():</span><br><span class="line">            print(key)</span><br><span class="line">            i = <span class="built_in">eval</span>(values)</span><br><span class="line">            list1.append(i)</span><br><span class="line">            <span class="keyword">if</span> i[<span class="string">&#x27;is_read&#x27;</span>] == <span class="number">0</span>:</span><br><span class="line">                length += <span class="number">1</span></span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;message&#x27;</span>: list1, <span class="string">&#x27;count&#x27;</span>: length&#125;)</span><br><span class="line">        <span class="comment"># uid = request.query_params.get(&#x27;id&#x27;)</span></span><br><span class="line">        <span class="comment"># count = Message.objects.filter(uid_id=uid, is_read=0).count()</span></span><br><span class="line">        <span class="comment"># message = Message.objects.filter(uid_id=uid).order_by(&#x27;is_read&#x27;, &#x27;-id&#x27;)</span></span><br><span class="line">        <span class="comment"># return Response(&#123;&#x27;message&#x27;: MessageSerializer(message, many=True).data, &#x27;count&#x27;: count&#125;)</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">put</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        wid = request.query_params.get(<span class="string">&#x27;id&#x27;</span>)</span><br><span class="line">        uid = request.data.get(<span class="string">&#x27;uid&#x27;</span>)</span><br><span class="line">        c = r.hgetall(<span class="string">&#x27;user%s&#x27;</span> % uid)</span><br><span class="line">        print(c)</span><br><span class="line">        <span class="keyword">for</span> key, values <span class="keyword">in</span> c.items():</span><br><span class="line">            print(key)</span><br><span class="line">            i = <span class="built_in">eval</span>(values)</span><br><span class="line">            print(i)</span><br><span class="line">            <span class="keyword">if</span> wid == i[<span class="string">&#x27;wid&#x27;</span>]:</span><br><span class="line">                r.hset(<span class="string">&#x27;user%s&#x27;</span> % uid, key, <span class="built_in">str</span>(&#123;<span class="string">&quot;name&quot;</span>: i[<span class="string">&#x27;name&#x27;</span>], <span class="string">&quot;wid&quot;</span>: wid, <span class="string">&quot;uid&quot;</span>: uid, <span class="string">&quot;is_read&quot;</span>: <span class="number">1</span>, <span class="string">&quot;is_ch&quot;</span>: <span class="number">0</span>&#125;))</span><br><span class="line">        <span class="keyword">return</span> Response(&#123;&#125;)</span><br></pre></td></tr></table></figure>
<h2 id="13）聊天系统"><a href="#13）聊天系统" class="headerlink" title="13）聊天系统"></a>13）聊天系统</h2><ul>
<li><strong>存储一份聊天记录，用websocket实现长连接进行聊天，将发送人id和接收人id进行拼接当key存入redis,存入类型 -&gt; list,将聊天记录按照字典的方式存入list</strong><ul>
<li><h3 id="websocket代码"><a href="#websocket代码" class="headerlink" title="websocket代码"></a>websocket代码</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@accept_websocket</span></span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">service</span>(<span class="params">request,user_id,uid</span>):</span></span><br><span class="line">    <span class="keyword">if</span> request.is_websocket():</span><br><span class="line">        <span class="keyword">while</span> <span class="number">1</span>:</span><br><span class="line">            time.sleep(<span class="number">1</span>)</span><br><span class="line">            list1 = []</span><br><span class="line">            list2 = []</span><br><span class="line">            time.sleep(<span class="number">1</span>)</span><br><span class="line">            list1.append(uid)</span><br><span class="line">            list1.append(user_id)</span><br><span class="line">            list1.sort()</span><br><span class="line">            key = <span class="built_in">str</span>(list1)</span><br><span class="line">            data = r.lrange(key)</span><br><span class="line">            user = User.objects.<span class="built_in">filter</span>(<span class="built_in">id</span>=user_id).first()</span><br><span class="line">            <span class="keyword">for</span> j <span class="keyword">in</span> data:</span><br><span class="line">                _ = &#123;&#125;</span><br><span class="line">                j = <span class="built_in">eval</span>(j)</span><br><span class="line">                _[<span class="string">&#x27;uid&#x27;</span>] = j[<span class="string">&#x27;uid&#x27;</span>]</span><br><span class="line">                _[<span class="string">&#x27;uname&#x27;</span>] = user.username</span><br><span class="line">                _[<span class="string">&#x27;name&#x27;</span>] = j[<span class="string">&quot;name&quot;</span>]</span><br><span class="line">                _[<span class="string">&#x27;jid&#x27;</span>] = j[<span class="string">&quot;jid&quot;</span>]</span><br><span class="line">                _[<span class="string">&#x27;ch&#x27;</span>] = j[<span class="string">&quot;ch&quot;</span>]</span><br><span class="line">                _[<span class="string">&#x27;read&#x27;</span>] = j[<span class="string">&quot;read&quot;</span>]</span><br><span class="line">                _[<span class="string">&#x27;date&#x27;</span>] = j[<span class="string">&#x27;date&#x27;</span>]</span><br><span class="line">                list2.append(_)</span><br><span class="line">            list2 = <span class="built_in">sorted</span>(list2, key=<span class="keyword">lambda</span> x: x[<span class="string">&#x27;date&#x27;</span>])</span><br><span class="line">            request.websocket.send(json.dumps(list2))</span><br></pre></td></tr></table></figure></li>
<li><h3 id="添加一个视图"><a href="#添加一个视图" class="headerlink" title="添加一个视图"></a>添加一个视图</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">MessAdd</span>(<span class="params">APIView</span>):</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span>(<span class="params">self, request</span>):</span></span><br><span class="line">        uid = request.data.get(<span class="string">&#x27;uid&#x27;</span>)</span><br><span class="line">        user_id = request.data.get(<span class="string">&#x27;user_id&#x27;</span>)</span><br><span class="line">        name = request.data.get(<span class="string">&#x27;name&#x27;</span>)</span><br><span class="line">        list1 = []</span><br><span class="line">        list1.append(<span class="built_in">str</span>(uid))</span><br><span class="line">        list1.append(<span class="built_in">str</span>(user_id))</span><br><span class="line">        list1.sort()</span><br><span class="line">        key = <span class="built_in">str</span>(list1)</span><br><span class="line">        date = time.time()</span><br><span class="line">        info = <span class="built_in">str</span>(&#123;<span class="string">&#x27;uid&#x27;</span>: uid, <span class="string">&#x27;name&#x27;</span>: name, <span class="string">&#x27;jid&#x27;</span>: user_id, <span class="string">&#x27;ch&#x27;</span>: <span class="number">0</span>, <span class="string">&#x27;read&#x27;</span>: <span class="number">0</span>,<span class="string">&#x27;date&#x27;</span>:date&#125;)</span><br><span class="line">        r.push(key, info)</span><br><span class="line">        <span class="keyword">return</span> Response(&#123;<span class="string">&#x27;msg&#x27;</span>: <span class="string">&#x27;发送成功&#x27;</span>&#125;)</span><br></pre></td></tr></table></figure></li>
<li><h3 id="vue端代码"><a href="#vue端代码" class="headerlink" title="vue端代码"></a>vue端代码</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br></pre></td><td class="code"><pre><span class="line">&lt;template&gt;</span><br><span class="line">  &lt;div&gt;</span><br><span class="line">    &lt;div&gt;</span><br><span class="line">      &lt;a-button <span class="built_in">type</span>=<span class="string">&quot;primary&quot;</span> @click=<span class="string">&quot;showModal&quot;</span>&gt;</span><br><span class="line">        创建聊天</span><br><span class="line">      &lt;/a-button&gt;</span><br><span class="line"></span><br><span class="line">      &lt;div&gt;</span><br><span class="line">        &lt;a-modal v-model=<span class="string">&quot;visible&quot;</span> title=<span class="string">&quot;选择聊天人&quot;</span> @ok=<span class="string">&quot;handleOk&quot;</span>&gt;</span><br><span class="line">          &lt;p v-<span class="keyword">for</span>=<span class="string">&quot;i in userlist&quot;</span> @click=<span class="string">&quot;showModal1(i.id)&quot;</span> v-<span class="keyword">if</span>=<span class="string">&quot;uid!=i.id&quot;</span>&gt;</span><br><span class="line">            &#123;&#123; i.username &#125;&#125;</span><br><span class="line">          &lt;/p&gt;</span><br><span class="line">        &lt;/a-modal&gt;</span><br><span class="line">      &lt;/div&gt;</span><br><span class="line"></span><br><span class="line">      &lt;a-modal v-model=<span class="string">&quot;visible1&quot;</span> title=<span class="string">&quot;聊天&quot;</span> @ok=<span class="string">&quot;handleOk1&quot;</span> width=<span class="string">&quot;40%&quot;</span>&gt;</span><br><span class="line">        &lt;a v-<span class="keyword">for</span>=<span class="string">&quot;j in listz&quot;</span>&gt;</span><br><span class="line">          &lt;p v-if=&quot;j.uid == uid&quot; style=&quot;text-align: right&quot;&gt;&#123;&#123; j.name &#125;&#125;&lt;/p&gt;</span><br><span class="line">          &lt;p v-else&gt;&#123;&#123; j.uname &#125;&#125;发送了: &#123;&#123; j.name &#125;&#125;&lt;/p&gt;</span><br><span class="line">        &lt;/a&gt;</span><br><span class="line">        &lt;a-input id=&quot;chat-message-input&quot; v-model=&quot;info&quot; type=&quot;text&quot;&gt;&lt;/a-input&gt;</span><br><span class="line">        &lt;a-button <span class="built_in">type</span>=<span class="string">&quot;primary&quot;</span> @click=<span class="string">&quot;sendmessage&quot;</span>&gt;</span><br><span class="line">          发送</span><br><span class="line">        &lt;/a-button&gt;</span><br><span class="line">      &lt;/a-modal&gt;</span><br><span class="line"></span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">  &lt;/div&gt;</span><br><span class="line">&lt;/template&gt;</span><br><span class="line"></span><br><span class="line">&lt;script&gt;</span><br><span class="line">export default &#123;</span><br><span class="line">  name: <span class="string">&quot;socket&quot;</span>,</span><br><span class="line">  data() &#123;</span><br><span class="line">    <span class="keyword">return</span> &#123;</span><br><span class="line">      info: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      listz: [],</span><br><span class="line">      visible: false,</span><br><span class="line">      userlist: [],</span><br><span class="line">      visible1: false,</span><br><span class="line">      user_id: <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">      uid: localStorage.getItem(<span class="string">&#x27;id&#x27;</span>),</span><br><span class="line">      socket:<span class="string">&#x27;&#x27;</span>,</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    showModal() &#123;</span><br><span class="line">      this.visible = true;</span><br><span class="line">    &#125;,</span><br><span class="line">    handleOk(e) &#123;</span><br><span class="line">      console.log(e);</span><br><span class="line">      this.visible = false;</span><br><span class="line">    &#125;,</span><br><span class="line">    showModal1(<span class="built_in">id</span>) &#123;</span><br><span class="line">      this.visible1 = true;</span><br><span class="line">      this.user_id = <span class="built_in">id</span></span><br><span class="line">      var _this = this</span><br><span class="line">      this.socket = new WebSocket(`ws:<span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">8000</span>/app2/service/$&#123;<span class="built_in">id</span>&#125;/$&#123;this.uid&#125;/`)</span><br><span class="line">      this.socket.onmessage = function (e) &#123;</span><br><span class="line">        _this.listz = JSON.parse(e.data)</span><br><span class="line">      &#125;;</span><br><span class="line">    &#125;,</span><br><span class="line">    handleOk1(e) &#123;</span><br><span class="line">      // console.log(e);</span><br><span class="line">      this.socket.close()</span><br><span class="line">      this.visible1 = false</span><br><span class="line">      this.user_id = <span class="string">&quot;&quot;</span></span><br><span class="line">      this.listz = []</span><br><span class="line">    &#125;,</span><br><span class="line">    sendmessage() &#123;</span><br><span class="line">      this.axios(&#123;</span><br><span class="line">        url: <span class="string">&#x27;http://127.0.0.1:8000/app2/mesadd/&#x27;</span>,</span><br><span class="line">        method: <span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">        data: &#123;<span class="string">&#x27;uid&#x27;</span>: this.uid, <span class="string">&#x27;user_id&#x27;</span>: this.user_id, <span class="string">&#x27;name&#x27;</span>: this.info&#125;</span><br><span class="line">      &#125;).then(res =&gt; &#123;</span><br><span class="line">        console.log(res.data)</span><br><span class="line">        <span class="keyword">if</span>(res.data.msg==<span class="string">&#x27;发送成功&#x27;</span>)&#123;</span><br><span class="line">          this.info = <span class="string">&quot;&quot;</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">  &#125;,</span><br><span class="line">  created() &#123;</span><br><span class="line">    this.axios(&#123;</span><br><span class="line">      url: <span class="string">&#x27;http://127.0.0.1:8000/app2/user/&#x27;</span></span><br><span class="line">    &#125;).then(res =&gt; &#123;</span><br><span class="line">      console.log(res.data)</span><br><span class="line">      this.userlist = res.data</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line">&lt;style scoped&gt;</span><br><span class="line"></span><br><span class="line">&lt;/style&gt;</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Z_SiTong</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhang-sitong.gitee.io/blogs/lz_20%20(%E6%8A%80%E6%9C%AF%E7%82%B9)/">https://zhang-sitong.gitee.io/blogs/lz_20%20(%E6%8A%80%E6%9C%AF%E7%82%B9)/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhang-sitong.gitee.io/blogs" target="_blank">欢迎来到小张的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blogs/tags/%E6%8A%80%E6%9C%AF%E7%82%B9/">技术点</a></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/03/29/nHq2BC7guU9e4cP.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blogs/lz_21/"><img class="prev-cover" src="https://i.loli.net/2021/04/01/8Ze57WtsNYROlo6.jpg" onerror="onerror=null;src='/blogs/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Git与gitee</div></div></a></div><div class="next-post pull-right"><a href="/blogs/lz_19/"><img class="next-cover" src="https://i.loli.net/2021/03/24/5IZl9AO2XLnjiWM.jpg" onerror="onerror=null;src='/blogs/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">WebSocket与Http</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="/blogs/img/%E5%8D%9A%E5%AE%A2%E5%A4%B4%E5%83%8F.jpg" onerror="this.onerror=null;this.src='/blogs/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Z_SiTong</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blogs/archives/"><div class="headline">文章</div><div class="length-num">29</div></a></div><div class="card-info-data-item is-center"><a href="/blogs/tags/"><div class="headline">标签</div><div class="length-num">12</div></a></div><div class="card-info-data-item is-center"><a href="/blogs/categories/"><div class="headline">分类</div><div class="length-num">12</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">This is my blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1%EF%BC%89ant-design%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">1.</span> <span class="toc-text">1）ant-design的使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%EF%BC%89IT%E6%96%B0%E9%97%BB%E7%BD%91%E7%AB%99"><span class="toc-number">2.</span> <span class="toc-text">2）IT新闻网站</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%EF%BC%89%E7%94%A8%E6%88%B7%E6%A0%A1%E9%AA%8C%E4%B8%89%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="toc-number">3.</span> <span class="toc-text">3）用户校验三种方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%EF%BC%89docker-%E9%95%9C%E5%83%8F-%E5%AE%B9%E5%99%A8-%E4%BB%93%E5%BA%93"><span class="toc-number">4.</span> <span class="toc-text">4）docker 镜像 容器 仓库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5%EF%BC%89redis"><span class="toc-number">5.</span> <span class="toc-text">5）redis</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%B4%A6%E5%8F%B7%E9%94%81%E5%AE%9A%E9%97%AE%E9%A2%98%EF%BC%9A%E4%BA%94%E5%88%86%E9%92%9F%E4%BB%A5%E5%86%85%E8%BE%93%E9%94%99%E4%BA%94%E6%AC%A1%E5%AF%86%E7%A0%81%EF%BC%8C%E9%94%81%E5%AE%9A%E8%B4%A6%E5%8F%B730%E5%88%86%E9%92%9F"><span class="toc-number">5.1.</span> <span class="toc-text">账号锁定问题：五分钟以内输错五次密码，锁定账号30分钟</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AC%AC%E4%B8%80%E6%AD%A5-%E5%85%88%E5%88%A4%E6%96%AD-%E7%94%A8%E6%88%B7%E5%90%8D-black-%E8%BF%99%E4%B8%AAkey-%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">5.1.1.</span> <span class="toc-text">第一步 先判断 用户名+black 这个key 是否存在</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AC%AC%E4%BA%8C%E6%AD%A5-%E5%90%91%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9B%E8%A1%8C%E8%AF%B7%E6%B1%82-%E7%99%BB%E5%BD%95"><span class="toc-number">5.1.2.</span> <span class="toc-text">第二步 向数据库进行请求 登录</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%AC%AC%E4%B8%89%E6%AD%A5-%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E6%98%AF%E7%AC%AC%E4%B8%80%E6%AC%A1%E8%BE%93%E5%85%A5%E9%94%99%E8%AF%AF"><span class="toc-number">5.1.3.</span> <span class="toc-text">第三步 判断是否是第一次输入错误</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E5%A6%82%E4%B8%8B"><span class="toc-number">5.2.</span> <span class="toc-text">代码如下</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6%EF%BC%89%E5%BC%82%E6%AD%A5"><span class="toc-number">6.</span> <span class="toc-text">6）异步</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%82%E6%AD%A5%E7%9A%84%E5%A5%BD%E5%A4%84%EF%BC%9A%E5%8F%AF%E4%BB%A5%E5%90%8C%E6%97%B6%E5%8F%91%E5%A4%9A%E4%B8%AA%E8%AF%B7%E6%B1%82"><span class="toc-number">6.1.</span> <span class="toc-text">异步的好处：可以同时发多个请求</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%82%E6%AD%A5%E5%8F%91%E9%80%81100%E6%AC%A1%E8%AF%B7%E6%B1%82"><span class="toc-number">6.2.</span> <span class="toc-text">异步发送100次请求:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%82%E6%AD%A5%E5%86%99%E6%96%87%E4%BB%B6"><span class="toc-number">6.3.</span> <span class="toc-text">异步写文件:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E9%98%9F%E5%88%97%E5%AE%9E%E7%8E%B0%E5%BC%82%E6%AD%A5%E4%BF%AE%E6%94%B9%E7%94%A8%E6%88%B7%E5%90%8D"><span class="toc-number">6.4.</span> <span class="toc-text">用队列实现异步修改用户名</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%B0%81%E8%A3%85redis"><span class="toc-number">6.4.1.</span> <span class="toc-text">1. 封装redis</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E5%AE%9E%E7%8E%B0%E5%BC%82%E6%AD%A5%E6%B6%88%E8%B4%B9"><span class="toc-number">6.4.2.</span> <span class="toc-text">2. 实现异步消费</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7%EF%BC%89%E6%9D%83%E9%99%90%E7%B3%BB%E7%BB%9F"><span class="toc-number">7.</span> <span class="toc-text">7）权限系统</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9D%83%E9%99%90%E6%A8%A1%E5%9E%8B%E4%B8%89%E7%A7%8D%EF%BC%9AACL-ABAC-RBAC"><span class="toc-number">7.1.</span> <span class="toc-text">权限模型三种：ACL&#x2F;ABAC&#x2F;RBAC</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90"><span class="toc-number">7.2.</span> <span class="toc-text">用户权限</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%8C%E6%88%90ACL%E6%9D%83%E9%99%90%E6%8E%A7%E5%88%B6%EF%BC%8C%E5%8D%95%E6%95%B0%E7%94%A8%E6%88%B7%E8%AE%BF%E9%97%AE%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86%EF%BC%8C%E5%8F%8C%E6%95%B0%E7%94%A8%E6%88%B7%E8%AE%BF%E9%97%AE%E7%94%A8%E6%88%B7%E8%AF%A6%E6%83%85"><span class="toc-number">7.2.1.</span> <span class="toc-text">完成ACL权限控制，单数用户访问用户管理，双数用户访问用户详情</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%AD%E9%97%B4%E4%BB%B6"><span class="toc-number">7.2.2.</span> <span class="toc-text">中间件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#settings%E9%85%8D%E7%BD%AE"><span class="toc-number">7.2.3.</span> <span class="toc-text">settings配置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E7%94%A8%E6%88%B7%E6%9D%83%E9%99%90%E8%A7%86%E5%9B%BE"><span class="toc-number">7.2.4.</span> <span class="toc-text">修改用户权限视图</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Vue%E8%B7%AF%E7%94%B1%E5%AE%88%E5%8D%AB"><span class="toc-number">7.2.5.</span> <span class="toc-text">Vue路由守卫</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8%EF%BC%89%E4%B8%89%E6%96%B9%E7%99%BB%E5%BD%95"><span class="toc-number">8.</span> <span class="toc-text">8）三方登录</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AE%E5%8D%9A%E4%B8%89%E6%96%B9%E7%99%BB%E5%BD%95"><span class="toc-number">8.1.</span> <span class="toc-text">微博三方登录</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%92%89%E9%92%89%E4%B8%89%E6%96%B9%E7%99%BB%E5%BD%95"><span class="toc-number">8.2.</span> <span class="toc-text">钉钉三方登录</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E9%92%89%E9%92%89%E4%BA%8C%E7%BB%B4%E7%A0%81"><span class="toc-number">8.2.1.</span> <span class="toc-text">获取钉钉二维码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96token"><span class="toc-number">8.2.2.</span> <span class="toc-text">获取token</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#vue%E5%9B%9E%E8%B0%83%E5%9C%B0%E5%9D%80"><span class="toc-number">8.2.3.</span> <span class="toc-text">vue回调地址</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#vue%E7%BB%91%E5%AE%9A%E7%94%A8%E6%88%B7"><span class="toc-number">8.2.4.</span> <span class="toc-text">vue绑定用户</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9%EF%BC%89%E6%97%A0%E9%99%90%E6%9E%81%E5%88%86%E7%B1%BB"><span class="toc-number">9.</span> <span class="toc-text">9）无限极分类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10%EF%BC%89MongoDB"><span class="toc-number">10.</span> <span class="toc-text">10）MongoDB</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11%EF%BC%89%E6%A0%88"><span class="toc-number">11.</span> <span class="toc-text">11）栈</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%88%EF%BC%9A%E5%85%88%E8%BF%9B%E5%90%8E%E5%87%BA"><span class="toc-number">11.1.</span> <span class="toc-text">栈：先进后出</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%86%99%E4%B8%80%E5%A5%97%E6%96%B9%E6%B3%95%EF%BC%8C%E5%9F%BA%E4%BA%8E%E6%A0%88%E7%B1%BB%EF%BC%8C%E5%AE%9E%E7%8E%B0bin%E6%96%B9%E6%B3%95%EF%BC%88%E5%8D%81%E8%BF%9B%E5%88%B6%E5%92%8C%E4%BA%8C%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%EF%BC%89"><span class="toc-number">11.2.</span> <span class="toc-text">写一套方法，基于栈类，实现bin方法（十进制和二进制转换）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12%EF%BC%89%E6%B6%88%E6%81%AF%E7%9B%92%E5%AD%90"><span class="toc-number">12.</span> <span class="toc-text">12）消息盒子</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#13%EF%BC%89%E8%81%8A%E5%A4%A9%E7%B3%BB%E7%BB%9F"><span class="toc-number">13.</span> <span class="toc-text">13）聊天系统</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#websocket%E4%BB%A3%E7%A0%81"><span class="toc-number">13.1.</span> <span class="toc-text">websocket代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0%E4%B8%80%E4%B8%AA%E8%A7%86%E5%9B%BE"><span class="toc-number">13.2.</span> <span class="toc-text">添加一个视图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue%E7%AB%AF%E4%BB%A3%E7%A0%81"><span class="toc-number">13.3.</span> <span class="toc-text">vue端代码</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blogs/lz_28/" title="多因子登录基础知识点"><img src="https://i.loli.net/2021/04/19/T9cDNdmovulPEbL.jpg" onerror="this.onerror=null;this.src='/blogs/img/404.jpg'" alt="多因子登录基础知识点"/></a><div class="content"><a class="title" href="/blogs/lz_28/" title="多因子登录基础知识点">多因子登录基础知识点</a><time datetime="2019-04-19T12:08:59.000Z" title="发表于 2019-04-19 20:08:59">2019-04-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blogs/lz_27/" title="基于Docker安装关系型数据库PostgrelSQL替代Mysql"><img src="https://i.loli.net/2021/04/19/QRXbxEvnLpBHuzI.jpg" onerror="this.onerror=null;this.src='/blogs/img/404.jpg'" alt="基于Docker安装关系型数据库PostgrelSQL替代Mysql"/></a><div class="content"><a class="title" href="/blogs/lz_27/" title="基于Docker安装关系型数据库PostgrelSQL替代Mysql">基于Docker安装关系型数据库PostgrelSQL替代Mysql</a><time datetime="2019-04-14T01:42:58.000Z" title="发表于 2019-04-14 09:42:58">2019-04-14</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blogs/lz_26/" title="json与pickle"><img src="https://i.loli.net/2021/04/13/DtnL4OVQM7bZjId.jpg" onerror="this.onerror=null;this.src='/blogs/img/404.jpg'" alt="json与pickle"/></a><div class="content"><a class="title" href="/blogs/lz_26/" title="json与pickle">json与pickle</a><time datetime="2019-04-12T07:48:41.000Z" title="发表于 2019-04-12 15:48:41">2019-04-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blogs/lz_25/" title="集合(set)的用法和使用场景，以及底层去重算法"><img src="https://i.loli.net/2021/04/08/Ji5dTUKsnoGjRBz.jpg" onerror="this.onerror=null;this.src='/blogs/img/404.jpg'" alt="集合(set)的用法和使用场景，以及底层去重算法"/></a><div class="content"><a class="title" href="/blogs/lz_25/" title="集合(set)的用法和使用场景，以及底层去重算法">集合(set)的用法和使用场景，以及底层去重算法</a><time datetime="2019-04-06T02:48:41.000Z" title="发表于 2019-04-06 10:48:41">2019-04-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blogs/lz_24/" title="openLDAP"><img src="https://i.loli.net/2021/04/07/nLeJybVMHwFNj7G.jpg" onerror="this.onerror=null;this.src='/blogs/img/404.jpg'" alt="openLDAP"/></a><div class="content"><a class="title" href="/blogs/lz_24/" title="openLDAP">openLDAP</a><time datetime="2019-03-31T08:52:13.000Z" title="发表于 2019-03-31 16:52:13">2019-03-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 <i style="color:#FF6A6A;animation: announ_animation 0.8s linear infinite;" class="fa fa-heartbeat"></i> Z_SiTong</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blogs/js/utils.js"></script><script src="/blogs/js/main.js"></script><script src="/blogs/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/gh/lete114/CDN/Sum/sakura.js"></script><script src="https://cdn.jsdelivr.net/gh/lete114/CDN/Sum/title.js"></script>null<script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>